<?php
namespace app\controllers\api\files;

use fate\http\Request;
use app\models\Files;
use app\libs\LibUser;

class ListController extends \fate\web\PureController {

    public function run() {
        $req = Request::getInstance();
        $p = $req->getQueryString('page');
        $pageSize = $req->getQueryString('pagesize');

        $uid = LibUser::getLoginUid();

        if(!is_numeric($uid)) {
            $this->ajaxReturn(null, 300002);
            exit;
        }

        if(!is_numeric($pageSize)) {
            $pageSize = 10;
        }
        if(!is_numeric($p)) {
            $p = 1;
        }

        $where = 'uid=' . $uid;

        $model = new Files();
        $total = $model->count($where);
        $ret = $model->getListByPage(
            'id,uid,uri,post_time',
            $where, $p, $pageSize);

        $this->ajaxReturn([
            'page_size' => $pageSize,
            'current' => $p,
            'total' => $total,
            'data' => $ret
        ]);
    }

}
